package com.android.mios;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.android.mios.adapter.CameraGridViewAdapter;
import com.android.mios.intenet.PollLoop;
import com.android.mios.model.Category;
import com.android.mios.model.Device;
import com.android.mios.util.Global;

import android.os.Bundle;
import android.widget.GridView;

public class CameraControlActivity extends DeviceBaseActivity {
	
	private List<Device> camearOfArray;
	private GridView mGridView;
	private CameraGridViewAdapter mCameraGridViewAdapter;
	public static final String DEVICE_ID = "com.android.miso.DEVICE_ID";
	public static final String DEVICE_NAME = "com.android.miso.DEVICE_NAME";
	public static final String SERIAL_NUMBER = "com.android.miso.SERIAL_NUMBER";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.camera_control_layout);
		initData();
		initView();
	}

	private void initData() {
		camearOfArray = new ArrayList<Device>();
		mCameraGridViewAdapter = new CameraGridViewAdapter(this, camearOfArray,
				R.layout.camera_item);
	}

	private void initView() {
		initGridView();
	}

	private void initGridView() {
		
		mGridView = (GridView) findViewById(R.id.GV_CameraControl);
		mGridView.setAdapter(mCameraGridViewAdapter);
	}

	@Override
	protected List<Device> getDeviceList(int serialNumber,int roomId) {
		
		Map<String, Device> allDevices = PollLoop.getInstance().getDevices();
		List<Device> devices = Device.findUnHideDevicesByCategory(allDevices, Category.CAMERA);
		if (roomId != -1)// -1 is all room
			devices = Device.findDevicesByRoom(devices,serialNumber, roomId);
		return devices;
	}
	
	@Override
	protected void updateDevice() {
		// TODO Auto-generated method stub
		camearOfArray.clear();
		camearOfArray.addAll(getDeviceList(Global.getInstance().getSerialNumber(),Global.getInstance().getRoomID()));
		mCameraGridViewAdapter.notifyDataSetChanged();
	}
}
